package com.school.empsys.service.impl;

import com.school.empsys.constants.AppealStatus;
import com.school.empsys.mapper.EmpAppealMapper;
import com.school.empsys.mapper.EmpSalaryMapper;
import com.school.empsys.model.EmpAppeal;
import com.school.empsys.model.EmpLeavePermit;
import com.school.empsys.model.EmpSalary;
import com.school.empsys.service.EmpAppealService;
import com.school.empsys.utils.UserUtil;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class EmpAppealServiceImpl implements EmpAppealService {

    @Autowired
    EmpAppealMapper empAppealMapper;
    @Autowired
    EmpSalaryMapper empSalaryMapper;


    @Override
    public int count(Map<String, Object> params) {
        return empAppealMapper.count(params);
    }

    @Override
    public List<EmpAppeal> list(Map<String, Object> params, Integer offset, Integer limit) {
        return empAppealMapper.list(params, offset, limit);
    }

    @Override
    public void save(EmpAppeal param) {
        EmpSalary empSalary = empSalaryMapper.selectByPrimaryKey(param.getSalaryId());
        param.setUserId(empSalary.getUserId());
        param.setCreateTime(new Date());
        param.setUpdateTime(new Date());
        param.setStatus(AppealStatus.SUBMIT.getName());
        empAppealMapper.insert(param);
    }

    @Override
    public EmpAppeal findOne(Integer id) {
        return empAppealMapper.selectByPrimaryKey(id);
    }

    @Override
    public void aduit(EmpAppeal param) {
        param.setUpdateTime(new Date());
        param.setHandler(UserUtil.getCurrentUser().getId().intValue());
        empAppealMapper.updateByPrimaryKeySelective(param);
    }
}
